<?php

namespace app\merchant\model;

use app\common\model\UserCoupon as UserCouponModel;

/**
 * 用户优惠券模型
 * Class UserCoupon
 * @package app\store\model
 */
class UserCoupon extends UserCouponModel
{
    /**
     * 获取优惠券列表
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList($query)
    {
        // 检索查询条件
        !empty($query) && $this->setWhere($query);

        return $this->alias("a")
            ->join('user b','a.user_id=b.user_id')
            ->field('a.*,b.nickName')
            ->order(['a.create_time' => 'desc'])
            ->paginate(15, false, [
                'query' => request()->request()
            ]);
    }

    /**
     * 设置检索查询条件
     * @param $query
     */
    private function setWhere($query)
    {

        if (isset($query['search']) && !empty($query['search'])) {
            $this->where('b.nickName', 'like', '%' . trim($query['search']) . '%');
        }

    }

}